package org.example.hospital_frontend.controller;

import org.example.hospital_frontend.common.Result;
import org.example.hospital_frontend.domain.Register;
import org.example.hospital_frontend.domain.User;
import org.example.hospital_frontend.service.RegisterService;
import org.example.hospital_frontend.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/admin/register")
public class AdminRegisterController {

    @Autowired
    private RegisterService registerService;
    
    @Autowired
    private UserService userService;

    // 获取未就诊挂号记录列表，包含患者和医生账号
    @GetMapping("/listForMedicalRecord")
    public Result listForMedicalRecord() {
        QueryWrapper<Register> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",0);
        List<Register> registers = registerService.list(queryWrapper);

        List<Map<String, Object>> resultList = new ArrayList<>();

        for (Register register : registers) {
            Map<String, Object> registerInfo = new HashMap<>();
            registerInfo.put("id", register.getId());

            // 获取患者信息
            User patient = userService.getById(register.getUserId());
            registerInfo.put("patientUsername", patient != null ? patient.getUsername() : "未知患者");

            // 获取医生信息
            User doctor = userService.getById(register.getDoctorId());
            registerInfo.put("doctorUsername", doctor != null ? doctor.getUsername() : "未知医生");

            resultList.add(registerInfo);
        }

        return Result.success(resultList);
    }

} 